package com.qili.service.base.impl;

import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.base.BaseMilepostJc;
import com.qili.mapper.base.BaseMilepostJcMapper;
import com.qili.service.base.BaseMilepostJcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaoyongke
 * @date 2020/11/3 基础 里程碑
 * @description
 */
@Service
public class BaseMilepostJcServiceImpl extends BaseServiceImpl<BaseMilepostJc,String> implements BaseMilepostJcService {

    @Autowired
    private BaseMilepostJcMapper baseMilepostMapper;

    @Override
    public BaseMapper<BaseMilepostJc, String> getMappser() {
        return baseMilepostMapper;
    }

    @Override
    public String selectBadtCode() {
        return baseMilepostMapper.selectBadtCode();
    }

//    @Override
//    public int addType(BaseDict baseDict) {
//        return baseMilepostMapper.addType(baseDict);
//    }


    @Override
    public List<BaseMilepostJc> selectMilepost(BaseMilepostJc baseMilepost) {
        return baseMilepostMapper.selectMilepost(baseMilepost);
    }

    @Override
    public List<BaseMilepostJc> selectMilepostListByStageId(String stageId, String milepostDictTypeCode) {
        Map paraMap = new HashMap();
        paraMap.put("stageId",stageId);
        paraMap.put("milepostDictTypeCode",milepostDictTypeCode);
        return baseMilepostMapper.selectMilepostListByStageId(paraMap);
    }

    @Override
    public boolean ifExited(BaseMilepostJc baseMilepost) {
        BaseMilepostJc exitedMilepost = new BaseMilepostJc();
        exitedMilepost.setStageId(baseMilepost.getStageId());
        exitedMilepost.setMilepostNo(baseMilepost.getMilepostNo());
        return baseMilepostMapper.selectOne(exitedMilepost) != null;
    }

    @Override
    public boolean checkCanEdit(BaseMilepostJc baseMilepost) {
        BaseMilepostJc oldMilepost = baseMilepostMapper.selectByPrimaryKey(baseMilepost);
        if(!oldMilepost.getMilepostNo().equals(baseMilepost.getMilepostNo())){
            return !ifExited(baseMilepost);
        }
        return true;
    }
}
